//
//  PhotoScrollView.m
//  MtimeMovie
//
//  Created by lllyyy on 15/7/23.
//  Copyright (c) 2015年 lllyyy. All rights reserved.
//

#import "PhotoScrollView.h"
#import "UIImageView+WebCache.h"
@implementation PhotoScrollView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        _imageView = [[UIImageView alloc]initWithFrame:self.bounds];
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        
        [self addSubview:_imageView];
        self.delegate = self;
        
        self.maximumZoomScale = 3;
        self.minimumZoomScale = 1;
    
        UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap)];
        //敲击次数
        doubleTap.numberOfTapsRequired = 2;
        //触摸手指的个数
        doubleTap.numberOfTouchesRequired = 1;
        [self addGestureRecognizer:doubleTap];
        
        
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap)];
        [self addGestureRecognizer:singleTap];
        
        [singleTap requireGestureRecognizerToFail:doubleTap];
    }
    return self;
}

- (void)doubleTap{
    if(self.zoomScale == 1 ){
        [self setZoomScale:3 animated:YES];
    }else{
        [self setZoomScale:1 animated:YES];
    }
}

- (void)singleTap{
    [[NSNotificationCenter defaultCenter]postNotificationName:@"HideNavgationBarNotification" object:nil];
    
}

- (void)setImageUrlStr:(NSString *)imageUrlStr{
    _imageUrlStr = imageUrlStr;
    [self setNeedsLayout];
}

- (void)layoutSubviews{
    [_imageView sd_setImageWithURL:[NSURL URLWithString:self.imageUrlStr]];
    
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return _imageView;
}
@end
